package com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.util;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.entity.SmsEnrollmentManagementOrgSetting;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.entity.resp.SmsEnrollmentManagementOrgSettingResp;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.mapper.SmsEnrollmentManagementOrgSettingMapper;
import com.xyht.sca_s.student_manage_system.modules.org.mapper.SmsOrgStructureMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class CollegeAndMajorUtil {
    public static final String ORIGIN_ORG_ID = "0"; //组织初始id  院系

    @Resource
    private SmsOrgStructureMapper smsOrgStructureMapper;
    @Resource
    private SmsEnrollmentManagementOrgSettingMapper smsEnrollmentManagementOrgSettingMapper;

    /**
     * @description 获取院系下方所有院校与专业
     *
     * @create 2024/1/16
     * @author dxn
    */
    public List<SmsEnrollmentManagementOrgSettingResp> getCollegeAndMajorList(){
        List<SmsEnrollmentManagementOrgSettingResp> list = smsEnrollmentManagementOrgSettingMapper.selectList(new LambdaQueryWrapper<SmsEnrollmentManagementOrgSetting>()
                .eq(SmsEnrollmentManagementOrgSetting::getParentId,ORIGIN_ORG_ID))
                .stream()
                .map(org->{
                    SmsEnrollmentManagementOrgSettingResp orgStructureResp = new SmsEnrollmentManagementOrgSettingResp();
                    BeanUtils.copyProperties(org,orgStructureResp);

                    List<SmsEnrollmentManagementOrgSettingResp> majorList = smsEnrollmentManagementOrgSettingMapper.selectList(new LambdaQueryWrapper<SmsEnrollmentManagementOrgSetting>()
                            .eq(SmsEnrollmentManagementOrgSetting::getParentId,org.getId()))
                            .stream()
                            .map(major->{
                                SmsEnrollmentManagementOrgSettingResp majorResp = new SmsEnrollmentManagementOrgSettingResp();
                                BeanUtils.copyProperties(major,majorResp);
                                return majorResp;
                            })
                            .collect(Collectors.toList());
                    orgStructureResp.setOrgList(majorList);
                    return orgStructureResp;
                })
                .collect(Collectors.toList());
        return list;
    }


}
